package org.axis2.client.rpc;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

/**
 * RPC客户端测试
 * Created by wevil on 16-10-26.
 */
public class RPCClient {
    public static void main(String[] args) throws AxisFault {
        try {
            RPCServiceClient serviceClient = new RPCServiceClient();
            EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/Hello");

            Options options = serviceClient.getOptions();
            options.setTo(targetEPR);

                    /*
                     * 这里的第一个参数namespaceURI，是我们访问Hello的wsdl 地址http://localhost:8080/axis2/services/Hello?wsdl
                     * ...
                     * <xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified" targetNamespace="http://ws.apache.org/axis2">
                     * ...
                     * 里targetNamespace的值
                     * */
            QName opAddEntry = new QName("http://ws.apache.org/axis2", "getString");
            Object[] opAddEntryArgs = new String[]{"wevil"};
            Class[] classes = new Class[]{String.class};

                    /*
                     * 如果被调用的WebService方法没有返回值，应使用RPCServiceClient类的invokeRobust方法，该方法只有两个参数，
                     * 他们的含义与invokeBlocking方法的前两个参数的含义相同。
                     * */
            System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
        } catch (AxisFault e) {
            e.printStackTrace();
        }
    }
}
